SERIAL_CONNECTION_TO_ARDUIONO := /dev/ttyUSB0
F_CPU := 16000000UL
MCU := atmega328p
CROSS_COMPILE := avr-
CC := $(CROSS_COMPILE)gcc
STRIP := $(CROSS_COMPILE)strip
STRIP := $(CROSS_COMPILE)strip
OBJCOPY := $(CROSS_COMPILE)objcopy

CFLAGS := -Wall -Os -mmcu=$(MCU) -DF_CPU=$(F_CPU)

%-stripped: %
	$(STRIP) $^ -o $@

%.srec: %-stripped
	$(OBJCOPY) -O srec $^ $@

%.hex: %-stripped
	$(OBJCOPY) -O ihex $^ $@

PROGRAM := blink
all: $(PROGRAM).hex
$(PROGRAM).hex: $(PROGRAM)-stripped
$(PROGRAM)-stripped: $(PROGRAM)
$(PROGRAM): $(PROGRAM).c

clean:
	rm -f $(PROGRAM) $(PROGRAM)-stripped $(PROGRAM).hex

install :
	avrdude -vvv -p m328p -b 57600 -P $(SERIAL_CONNECTION_TO_ARDUIONO) -c stk500v1 -F -e -U flash:w:$(PROGRAM).hex
	#avrdude -p m328p -c stk500v2 -P $(SERIAL_CONNECTION_TO_ARDUIONO) -U $(PROGRAM).hex
	#avrdude -p m168 -b 19200 -P $(SERIAL_CONNECTION_TO_ARDUIONO) -c stk500v1 -F -u -U flash:w:$(PROGRAM).hex


.PHONY: all clean install
	
